// 将二维数组中的每个子数组按升序排序
export function sortNestedArray(arr) {
  return arr.map(subArray => subArray.slice().sort((a, b) => a - b))
}

// 将数组拍平至一维，然后升序排序
export function flattenAndSort(arr) {
  return arr.flat().sort((a, b) => a - b)
}

// kill number array
export function getRemainingNumbers(inputArray) {
  // 定义1至49的数字数组
  const numbers = Array.from({ length: 49 }, (_, i) => i + 1)

  // 将传入的数组元素都转为整数并去重
  const excludedNumbers = inputArray.map(Number).filter((num) => !isNaN(num))

  // 过滤掉numbers中包含在excludedNumbers里的数字
  const result = numbers.filter((num) => !excludedNumbers.includes(num))

  return result
}

// fullArray kill excludeArray
export function getRemainingNumbersFromArrays(fullArray, excludeArray) {
  // 将传入的 fullArray 和 excludeArray 的元素都转为整数
  const fullNumbers = fullArray.map(Number).filter((num) => !isNaN(num))
  const excludeNumbers = excludeArray.map(Number).filter((num) => !isNaN(num))

  // 过滤掉 fullNumbers 中包含在 excludeNumbers 里的数字
  const result = fullNumbers.filter((num) => !excludeNumbers.includes(num))

  return result
}

// 数组去重
export function uniqueArray(array) {
  return Array.from(new Set(array))
}
